import {
  getUserInfo
} from "../../../utils/http";
import {
  querycrelist
} from "../../../api/pm";
const {
  eventBus
} = getApp().globalData;
const globalData = getApp().globalData;
const {
  userInfo
} = globalData
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isData: false,
    pageNum: 1,
    list: null,
    userInfo: userInfo,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    eventBus.on("shortcutItem", this.handleShortcutItem);
    this.setData({
      userInfo: globalData.userInfo
    })
    getUserInfo(() => {
      this.setData({
        userInfo: globalData.userInfo
      })
    })
    this.querycrelist();
  },
  goBack() {
    wx.navigateBack()
  },
  querycrelist() {
    wx.showLoading({
      title: '加载中',
    });
    querycrelist({
      data: {
        "pageNum": this.data.pageNum,
        "pageSize": 10
      },
      callBack: (res) => {
        let oldData
        if (!this.data.list) {
          oldData = []
        } else {
          oldData = this.data.list
        }
        let newData = oldData.concat(res.rows)


        console.log(newData)
        this.setData({
          list: newData
        })
        if (this.data.list.length == res.total || res.rows.length < 10) {
          this.setData({
            isData: true
          })
        }
        wx.stopPullDownRefresh();
        wx.hideLoading();





      }

    })
  },

  onReachBottom() {

    if (this.data.isData) return;
    console.log('我触底了');
    this.data.pageNum = this.data.pageNum + 1;
    this.querycrelist();

  },



})